<template>
    <div class="update">
         <h2 style="font-size:25px; padding:0;margin-bottom:30px;">修改密码</h2>

        <div>
            <el-form :model="ruleForm" status-icon :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
                <el-form-item label="密码" prop="pass">
                    <el-input type="password" v-model="ruleForm.pass" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="确认密码" prop="checkPass">
                    <el-input type="password" v-model="ruleForm.checkPass" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item >
                    <el-button type="primary" @click="submitForm()">提交</el-button>
                    <router-link to="/center" ><el-button type="primary">返回</el-button></router-link>
                </el-form-item>
            </el-form>
        </div>
    </div>
</template>

<script>
  export default {
    data() {
      
      var validatePass = (rule, value, callback) => {
        if (value === '') {
          callback(new Error('请输入密码'));
        } else {
          if (this.ruleForm.checkPass !== '') {
            this.$refs.ruleForm.validateField('checkPass');
          }
          callback();
        }
      };
      var validatePass2 = (rule, value, callback) => {
        if (value === '') {
          callback(new Error('请再次输入密码'));
        } else if (value !== this.ruleForm.pass) {
          callback(new Error('两次输入密码不一致!'));
        } else {
          callback();
        }
      };
      return {
        ruleForm: {
          pass: '',
          checkPass: '',
         
        },
        rules: {
          pass: [
            { validator: validatePass, trigger: 'blur' }
          ],
          checkPass: [
            { validator: validatePass2, trigger: 'blur' }
          ],
          
        }
      };
    },
    methods: {
      submitForm() {
          this.id=window.localStorage.getItem("uid");
          console.log(this.ruleForm.pass)
          console.log(this.id)
        this.$axios.get(
        "/updateUser.do?user_pass="+this.ruleForm.pass
        +"&user_id=" +this.id
        )
       .then((response) => {
           if(response.data>0){
                alert('修改成功!')
           }else{
               alert('修改失败！')
           }
       })
      },

    }
  }
</script>

<style scoped>
.update{
    width: 80%;
    border: 1px solid #999;
    text-align: center;
    margin: auto;
    margin-top: 100px;
    padding-top: 40px;
    padding-right: 20px;
    
}
.el-button--primary {
    margin-right: 25px;
}
</style>